<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<title>课程管理</title>
		<link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
		<script src="https://www.layuicdn.com/layui/layui.js"></script>
	</head>
	<body>
		<div class="layui-col-xs10 layui-col-xs-offset1">
			<div class="layui-form" style="height: 450px;margin-top: 3%;">
			  <table class="layui-table">
			    <colgroup>
			      <col width="100">
			      <col width="200">
			      <col width="100">
			      <col width="100">
			      <col width="250">
			      <col>
			    </colgroup>
			    <thead>
			      <tr>
			        <th>课程码</th>
			        <th>课程名称</th>
			        <th>课程状态</th>
			        <th>课程限制</th>
			        <th>课程简介</th>
			        <th>操作</th>
			      </tr> 
			    </thead>
			    <tbody>
			      <tr th:each="course : ${courses}">
			        <td th:text="${course.id}"></td>
			        <td><a th:href="@{'info/' + ${course.id}}" th:text="${course.name}"></a></td>
			        <td th:switch="${course.status}">
			        	<span th:case="0">未考试</span>
			        	<span th:case="1">考试中</span>
			        	<span th:case="2">考试结束</span>
			        </td>
			        <td>
			        	<span th:if="${course.allow}">允许加入</span>
			        	<span th:if="not ${course.allow}">禁止加入</span>
			        </td>
			        <td th:text="${course.description}"></td>
			        <td>
			        	<button type="button" class="layui-btn layui-btn-warm layui-btn-sm" th:onclick="window.location.href = 'test?id=[[${course.id}]]'" th:disabled="${course.status == 1} ? 'false' : 'true'" th:classappend="${course.status == 1} ? '' : 'layui-btn-disabled'">开始考试</button>
		        		<button type="button" class="layui-btn layui-btn-sm" th:onclick="exit([[${course.id}]])">退出课程</button>
			        </td>
			      </tr>
			    </tbody>
			  </table>
			</div>
			<!-- 分页 -->
			<div class="layui-col-xs4 layui-col-xs-offset4">
				<button th:onclick="window.location.href = 'course?page=[[${page-1}]]&limit=9'" type="button" class="layui-btn" th:disabled="${page > 1} ? '' : 'disabled'" th:classappend="${page > 1} ? '' : 'layui-btn-disabled'">上一页</button>
				<span th:text="${page}"></span>
				<button th:onclick="window.location.href = 'course?page=[[${page+1}]]&limit=9'" type="button" class="layui-btn" th:disabled="${page < count} ? '' : 'disabled'" th:classappend="${page < count} ? '' : 'layui-btn-disabled'">下一页</button>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		function exit(id){
			layui.use('layer', function(){
				var layer = layui.layer;
				layer.confirm('真的退出？', {
					icon: 3, 
					title:'提示'
				}, function(index){
					var load = layer.load(1);
					$.getJSON('course/exit', {
						id: id
					}, function(res){
						layer.close(load);
						if(res.code == '00000'){
							layer.alert('退出成功', function(){
								location.reload();
							});
						}else{
							layer.alert(res.message);
						}
					})
					layer.close(index);
				});
				
			});
		}
		function test(id){
			
		}
	</script>
</html>